home *** CD-ROM | disk | FTP | other *** search
/ Clickx 115 / Clickx 115.iso / software / tools / windows / tails-i386-0.16.iso / live / filesystem.squashfs / usr / lib / perl5 / IO / Tty.pm < prev   
Encoding:
Perl POD Document  |  2010-02-05  |  7.3 KB  |  286 lines

  1. # Documentation at the __END__
  2. # -*-cperl-*-
  3.  
  4. package IO::Tty;
  5.  
  6. use IO::Handle;
  7. use IO::File;
  8. use IO::Tty::Constant;
  9. use Carp;
  10.  
  11. require POSIX;
  12. require DynaLoader;
  13.  
  14. use vars qw(@ISA $VERSION $XS_VERSION $CONFIG $DEBUG);
  15.  
  16. $VERSION = 1.08;
  17. $XS_VERSION = "1.08";
  18. @ISA = qw(IO::Handle);
  19.  
  20. eval { local $^W = 0; undef local $SIG{__DIE__}; require IO::Stty };
  21. push @ISA, "IO::Stty" if (not $@);  # if IO::Stty is installed
  22.  
  23. BOOT_XS: {
  24.     # If I inherit DynaLoader then I inherit AutoLoader and I DON'T WANT TO
  25.     require DynaLoader;
  26.  
  27.     # DynaLoader calls dl_load_flags as a static method.
  28.     *dl_load_flags = DynaLoader->can('dl_load_flags');
  29.  
  30.     do {
  31.     defined(&bootstrap)
  32.         ? \&bootstrap
  33.         : \&DynaLoader::bootstrap
  34.     }->(__PACKAGE__);
  35. }
  36.  
  37. sub import {
  38.     IO::Tty::Constant->export_to_level(1, @_);
  39. }
  40.  
  41. sub open {
  42.     my($tty,$dev,$mode) = @_;
  43.  
  44.     IO::File::open($tty,$dev,$mode) or
  45.     return undef;
  46.  
  47.     $tty->autoflush;
  48.  
  49.     1;
  50. }
  51.  
  52. sub clone_winsize_from {
  53.   my ($self, $fh) = @_;
  54.   croak "Given filehandle is not a tty in clone_winsize_from, called"
  55.     if not POSIX::isatty($fh);  
  56.   return 1 if not POSIX::isatty($self);  # ignored for master ptys
  57.   my $winsize = " "x1024; # preallocate memory
  58.   ioctl($fh, &IO::Tty::Constant::TIOCGWINSZ, $winsize)
  59.     and ioctl($self, &IO::Tty::Constant::TIOCSWINSZ, $winsize)
  60.       and return 1;
  61.   warn "clone_winsize_from: error: $!" if $^W;
  62.   return undef;
  63. }
  64.  
  65. sub set_raw($) {
  66.   require POSIX;
  67.   my $self = shift;
  68.   return 1 if not POSIX::isatty($self);
  69.   my $ttyno = fileno($self);
  70.   my $termios = new POSIX::Termios;
  71.   unless ($termios) {
  72.     warn "set_raw: new POSIX::Termios failed: $!";
  73.     return undef;
  74.   }
  75.   unless ($termios->getattr($ttyno)) {
  76.     warn "set_raw: getattr($ttyno) failed: $!";
  77.     return undef;
  78.   }
  79.   $termios->setiflag(0);
  80.   $termios->setoflag(0);
  81.   $termios->setlflag(0);
  82.   $termios->setcc(&POSIX::VMIN, 1);
  83.   $termios->setcc(&POSIX::VTIME, 0);
  84.   unless ($termios->setattr($ttyno, &POSIX::TCSANOW)) {
  85.     warn "set_raw: setattr($ttyno) failed: $!";
  86.     return undef;
  87.   }
  88.   return 1;
  89. }
  90.  
  91.  
  92. 1;
  93.  
  94. __END__
  95.  
  96. =head1 NAME
  97.  
  98. IO::Tty - Low-level allocate a pseudo-Tty, import constants.
  99.  
  100. =head1 VERSION
  101.  
  102. 1.08
  103.  
  104. =head1 SYNOPSIS
  105.  
  106.     use IO::Tty qw(TIOCNOTTY);
  107.     ...
  108.     # use only to import constants, see IO::Pty to create ptys.
  109.  
  110. =head1 DESCRIPTION
  111.  
  112. C<IO::Tty> is used internally by C<IO::Pty> to create a pseudo-tty.
  113. You wouldn't want to use it directly except to import constants, use
  114. C<IO::Pty>.  For a list of importable constants, see
  115. L<IO::Tty::Constant>.
  116.  
  117. Windows is now supported, but ONLY under the Cygwin
  118. environment, see L<http://sources.redhat.com/cygwin/>.
  119.  
  120. Please note that pty creation is very system-dependend.  From my
  121. experience, any modern POSIX system should be fine.  Find below a list
  122. of systems that C<IO::Tty> should work on.  A more detailed table
  123. (which is slowly getting out-of-date) is available from the project
  124. pages document manager at SourceForge
  125. L<http://sourceforge.net/projects/expectperl/>.
  126.  
  127. If you have problems on your system and your system is listed in the
  128. "verified" list, you probably have some non-standard setup, e.g. you
  129. compiled your Linux-kernel yourself and disabled ptys (bummer!).
  130. Please ask your friendly sysadmin for help.
  131.  
  132. If your system is not listed, unpack the latest version of C<IO::Tty>,
  133. do a C<'perl Makefile.PL; make; make test; uname -a'> and send me
  134. (F<RGiersig@cpan.org>) the results and I'll see what I can deduce from
  135. that.  There are chances that it will work right out-of-the-box...
  136.  
  137. If it's working on your system, please send me a short note with
  138. details (version number, distribution, etc. 'uname -a' and 'perl -V'
  139. is a good start; also, the output from "perl Makefile.PL" contains a
  140. lot of interesting info, so please include that as well) so I can get
  141. an overview.  Thanks!
  142.  
  143.  
  144. =head1 VERIFIED SYSTEMS, KNOWN ISSUES
  145.  
  146. This is a list of systems that C<IO::Tty> seems to work on ('make
  147. test' passes) with comments about "features":
  148.  
  149. =over 4
  150.  
  151. =item * AIX 4.3
  152.  
  153. Returns EIO instead of EOF when the slave is closed.  Benign.
  154.  
  155. =item * AIX 5.x
  156.  
  157. =item * FreeBSD 4.4
  158.  
  159. EOF on the slave tty is not reported back to the master.
  160.  
  161. =item * OpenBSD 2.8
  162.  
  163. The ioctl TIOCSCTTY sometimes fails.  This is also known in
  164. Tcl/Expect, see http://expect.nist.gov/FAQ.html
  165.  
  166. EOF on the slave tty is not reported back to the master.
  167.  
  168. =item * Darwin 7.9.0
  169.  
  170. =item * HPUX 10.20 & 11.00
  171.  
  172. EOF on the slave tty is not reported back to the master.
  173.  
  174. =item * IRIX 6.5
  175.  
  176. =item * Linux 2.2.x & 2.4.x
  177.  
  178. Returns EIO instead of EOF when the slave is closed.  Benign.
  179.  
  180. =item * OSF 4.0
  181.  
  182. EOF on the slave tty is not reported back to the master.
  183.  
  184. =item * Solaris 8, 2.7, 2.6
  185.  
  186. Has the "feature" of returning EOF just once?!
  187.  
  188. EOF on the slave tty is not reported back to the master.
  189.  
  190. =item * Windows NT/2k/XP (under Cygwin)
  191.  
  192. When you send (print) a too long line (>160 chars) to a non-raw pty,
  193. the call just hangs forever and even alarm() cannot get you out.
  194. Don't complain to me...
  195.  
  196. EOF on the slave tty is not reported back to the master.
  197.  
  198. =item * z/OS
  199.  
  200. =back
  201.  
  202. The following systems have not been verified yet for this version, but
  203. a previous version worked on them:
  204.  
  205. =over 4
  206.  
  207. =item * SCO Unix
  208.  
  209. =item * NetBSD
  210.  
  211. probably the same as the other *BSDs...
  212.  
  213. =back
  214.  
  215. If you have additions to these lists, please mail them to
  216. E<lt>F<RGiersig@cpan.org>E<gt>.
  217.  
  218.  
  219. =head1 SEE ALSO
  220.  
  221. L<IO::Pty>, L<IO::Tty::Constant>
  222.  
  223.  
  224. =head1 MAILING LISTS
  225.  
  226. As this module is mainly used by Expect, support for it is available
  227. via the two Expect mailing lists, expectperl-announce and
  228. expectperl-discuss, at
  229.  
  230.   http://lists.sourceforge.net/lists/listinfo/expectperl-announce
  231.  
  232. and
  233.  
  234.   http://lists.sourceforge.net/lists/listinfo/expectperl-discuss
  235.  
  236.  
  237. =head1 AUTHORS
  238.  
  239. Originally by Graham Barr E<lt>F<gbarr@pobox.com>E<gt>, based on the
  240. Ptty module by Nick Ing-Simmons E<lt>F<nik@tiuk.ti.com>E<gt>.
  241.  
  242. Now maintained and heavily rewritten by Roland Giersig
  243. E<lt>F<RGiersig@cpan.org>E<gt>.
  244.  
  245. Contains copyrighted stuff from openssh v3.0p1, authored by Tatu
  246. Ylonen <ylo@cs.hut.fi>, Markus Friedl and Todd C. Miller
  247. <Todd.Miller@courtesan.com>.  I also got a lot of inspiry from the pty
  248. code in Xemacs.
  249.  
  250.  
  251. =head1 COPYRIGHT
  252.  
  253. Now all code is free software; you can redistribute it and/or modify
  254. it under the same terms as Perl itself.
  255.  
  256. Nevertheless the above AUTHORS retain their copyrights to the various
  257. parts and want to receive credit if their source code is used.
  258. See the source for details.
  259.  
  260.  
  261. =head1 DISCLAIMER
  262.  
  263. THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESS OR IMPLIED
  264. WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
  265. MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
  266. IN NO EVENT SHALL THE AUTHORS BE LIABLE FOR ANY DIRECT, INDIRECT,
  267. INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
  268. BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS
  269. OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
  270. ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR
  271. TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE
  272. USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH
  273. DAMAGE.
  274.  
  275. In other words: Use at your own risk.  Provided as is.  Your mileage
  276. may vary.  Read the source, Luke!
  277.  
  278. And finally, just to be sure:
  279.  
  280. Any Use of This Product, in Any Manner Whatsoever, Will Increase the
  281. Amount of Disorder in the Universe. Although No Liability Is Implied
  282. Herein, the Consumer Is Warned That This Process Will Ultimately Lead
  283. to the Heat Death of the Universe.
  284.  
  285. =cut
  286.